# pages/baidu_page.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class BaiduPage:
    """百度 AI 对话版页面"""

    def __init__(self, driver):
        self.driver = driver

    # 1. 打开百度（服务器会返回 AI 版）
    def open(self):
        self.driver.get("https://www.baidu.com")

    # 2. 输入问题
    def input_question(self, text):
        box = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.ID, "chat-textarea"))
        )
        box.clear()
        box.send_keys(text)

    # 3. 点击“百度一下”
    def click_search(self):
        self.driver.find_element(By.ID, "chat-submit-button").click()

    # 4. 等待回答出现并返回文本，方便断言
    def get_answer(self):
        WebDriverWait(self.driver, 10).until(EC.title_contains("搜索"))
        return self.driver.title
